package com.fay.designPattern.principles.solid;



/**
 * @Title:
 * @Description:
 * @Author Fay Wang
 * @Date 2022/3/1 15:41
 * @Version 1.0
 */
public class OcpAlert {
    private AlertRule rule;
    private Notification notification;

    public OcpAlert(AlertRule alertRule, Notification notification) {
        this.rule = alertRule;
        this.notification = notification;
    }
    // 第一处修改:入参
    public void check(String api, long requestCount, long errorCount, long durationOfSeconds, long timeoutCount) {
        long tps = requestCount / durationOfSeconds;
        if (tps > rule.getMatchedRule(api).getMaxTps()) {
            notification.notify(NotificationEmergencyLevel.URGENCY, "...");
        }
        if (errorCount > rule.getMatchedRule(api).getMaxErrorCount()) {
            notification.notify(NotificationEmergencyLevel.SEVERE, "...");
        }
        // 第二处修改：处理逻辑
        if (timeoutCount > rule.getMatchedRule(api).getMaxTimeoutTps()) {
            notification.notify(NotificationEmergencyLevel.URGENCY, "...");
        }
    }
}
